package com.example.demoserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demoserver.entity.TrainQuestions;
import com.example.demoserver.service.TrainQuestionsService;
import com.example.demoserver.mapper.TrainQuestionsMapper;
import com.example.demoserver.service.TrainUserquesionsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【train_questions】的数据库操作Service实现
* @createDate 2024-11-01 14:08:05
*/
@Service
public class TrainQuestionsServiceImpl extends ServiceImpl<TrainQuestionsMapper, TrainQuestions>
    implements TrainQuestionsService{
    @Autowired
    TrainQuestionsMapper trainQuestionsMapper;

    @Override
    public List<TrainQuestions> select(String searchCode) {
        QueryWrapper<TrainQuestions> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByAsc("orderIndex");
        if(searchCode!=null){

            queryWrapper.like("queCode",searchCode).or().like("queTitle",searchCode);

            return trainQuestionsMapper.selectList(queryWrapper);
        }
        return trainQuestionsMapper.selectList(queryWrapper);

    }

    @Override
    public Integer deleteAll() {
        QueryWrapper<TrainQuestions> queryWrapper=new QueryWrapper<>();

        return trainQuestionsMapper.delete(queryWrapper);
    }

    @Override
    public PageInfo<TrainQuestions> selectPage(Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        QueryWrapper<TrainQuestions> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("orderIndex");
        List<TrainQuestions> l=trainQuestionsMapper.selectList(queryWrapper);
        PageInfo<TrainQuestions> pageInfo = new PageInfo<TrainQuestions>(l);
        return pageInfo;
    }

    @Override
    public TrainQuestions selectById(Integer id) {

        return trainQuestionsMapper.selectById(id);
    }

    @Override
    public TrainQuestions selectByqueId(Integer queId) {
        QueryWrapper<TrainQuestions> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("queId",queId);
        return trainQuestionsMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer deleteById(Integer id) {

        return trainQuestionsMapper.deleteById(id);
    }


}




